package com.damai.push;

import java.io.IOException;
import java.util.Map;

import org.citywithincity.jobqueue.TaskQueue;

import com.damai.push.JPushModel.PushBuilder;
import com.damai.push.JPushModel.PushReport;

public class PushService {
	private static PushBuilder builder(){
		return new PushBuilder();
	}
	public void sendByDeviceID(String title, Map<String, Object> data, String alias) throws IOException {
		send(builder().platformAll().setAlias(alias).setContent(title, data).setOptions());
	}
	/**
	 * 
	 * @param title		推送标题
	 * @param content   推送内容
	 * @param report	进程报告（可空)
	 * @param data		附带数据（可空）
	 */
	public void notification(String title,Object content,PushReport report,Object data){
		send(builder().setData(data).setReport(report).platformAll().audienceAll().setContent(title, content).setOptions());
	}
	public void alias(String phone,String title,Object content){
		send(builder().platformAll().setAlias(phone).setContent(title, content).setOptions());
	}
	private void send(PushBuilder builder) {
		TaskQueue.getInstance().add(builder);
	}
	public void sendByPushId(String title, Map<String, Object> data, String regId) throws IOException {
		send(builder().platformAll().setRegId(regId).setContent(title, data).setOptions());
	}
	public void sendByPushAlias(String title, Map<String, Object> data, String regId) throws IOException {
		send(builder().platformAll().setAlias(regId).setContent(title, data).setOptions());
	}
}
